//  
//    UIView+SetRect.swift
//    Swift-Extension
//  
//    Created by tianXin on 2017/7/21.
//    Copyright © 2017年 田鑫. All rights reserved.
//  

import Foundation
import UIKit

extension UIView {
    //  / x
    var x : CGFloat {
        
        get {return frame.origin.x}
        
        set(newValue) {
            
            var tmpFrame      = frame
            tmpFrame.origin.x = newValue
            frame             = tmpFrame
        }
    }
    
    //  / y
    var  y : CGFloat {
        
        get {return frame.origin.y}
        
        set(newValue) {
            
            var tmpFrame      = frame
            tmpFrame.origin.y = newValue
            frame             = tmpFrame
        }
    }
    
    //  /width
    var width : CGFloat {
        
        get {return frame.width}
        
        set(newValue) {
            
            var tmpFrame        = frame
            tmpFrame.size.width = newValue
            frame               = tmpFrame
        }
    }
    
    //  /height
    var height : CGFloat {
        
        get {return frame.height}
        
        set(newValue) {
            
            var tmpFrame         = frame
            tmpFrame.size.height = newValue
            frame                = tmpFrame
        }
    }
    
    //  /origin
    var origin : CGPoint {
        
        get {return frame.origin}
        
        set(newValue) {
            
            var tmpFrame      = frame
            tmpFrame.origin   = newValue
            frame             = tmpFrame
        }
    }
    
    //  /size
    var size  : CGSize {
        
        get {return frame.size}
        
        set(newValue) {
            
            var tmpFrame      = frame
            tmpFrame.size     = newValue
            frame             = tmpFrame
        }
    }
    
    //  / left
    var left : CGFloat {
        
        get { return frame.origin.x}
        
        set(newVal) {
            
            var tmpFrame      = frame
            tmpFrame.origin.x = newVal
            frame             = tmpFrame
        }
    }
    
    //  / right
    var right : CGFloat {
        
        get { return frame.origin.x + frame.size.width}
        
        set(newVal) {
            
            var tmpFrame      = frame
            tmpFrame.origin.x = newVal - frame.size.width
            frame             = tmpFrame
        }
    }
    
    //  / top
    var top : CGFloat {
        
        get { return frame.origin.y}
        
        set(newVal) {
            
            var tmpFrame      = frame
            tmpFrame.origin.y = newVal
            frame = tmpFrame
        }
    }
    
    //  / bottom
    var bottom : CGFloat {
        
        get { return frame.origin.y + frame.size.height}
        
        set(newVal) {
            
            var tmpFrame      = frame
            tmpFrame.origin.y = newVal - frame.size.height
            frame             = tmpFrame
        }
    }
    
    //  /centerPosition
    var centerPosition : CGPoint {
        
        get {return center}
        
        set(newValue) {center = newValue}
    }
    
    //  / centerX
    var centerX : CGFloat {
        
        get { return center.x}
        set(newVal) { center = CGPoint(x: newVal, y: center.y)}
    }
    
    //  / centerY
    var centerY : CGFloat {
        
        get { return center.y}
        set(newVal) { center = CGPoint(x: center.x, y: newVal)}
    }
    
    //  / middleX
    var middleX : CGFloat {
        
        get { return bounds.width / 2}
    }
    
    //  / middleY
    var middleY : CGFloat {
        
        get { return bounds.height / 2}
    }
    
    //  / middlePoint
    var middlePoint : CGPoint {
        
        get { return CGPoint(x: bounds.width / 2, y: bounds.height / 2)}
    }
}
